package com.zengqingfa.designpattern.behavior.strategy;

import java.util.Arrays;
import java.util.Comparator;

/**
 *
 * @fileName: Client
 * @author: zengqf3
 * @date: 2021-4-18 23:02
 * @description:
 */
public class Client {

    public static void main(String[] args) {
        Integer[] intArray = {89, 3, 67, 12, 45};
        // 匿名内部类无需专门定义形态完整的类，只需指明新创建的实例从哪个接口扩展而来
        Arrays.sort(intArray, new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return Integer.compare(o1, o2); // 倒过来的参数顺序变成了降序
            }
        });
        String descDesc = "intArray采取匿名内部类的降序结果为：";
        for (Integer item : intArray) {
            descDesc = descDesc + item + ", ";
        }
        System.out.println(descDesc);
        //降序
        Arrays.sort(intArray, (o1, o2) -> Integer.compare(o2, o1));
        String descDesc2 = "intArray采取匿名内部类的降序结果为：";
        for (Integer item : intArray) {
            descDesc2 = descDesc2 + item + ", ";
        }
        System.out.println(descDesc2);
    }
}
